package com.kkelectronics.w2b.devplugin.codegenerator.core.databean;

import org.eclipse.jdt.core.dom.AST;
import org.eclipse.jdt.core.dom.Javadoc;
import org.eclipse.jdt.core.dom.MethodDeclaration;
import org.eclipse.jdt.core.dom.SingleVariableDeclaration;
import org.eclipse.jdt.core.dom.Type;

import com.kkelectronics.w2b.devplugin.codegenerator.model.Field;

@SuppressWarnings("static-access")
public class CodeGenerator {

	public static MethodDeclaration genGetMethodSignature(final AST ast, final Field field) {
		final MethodDeclaration getMD = ast.newMethodDeclaration();
		getMD.setName(ast.newSimpleName("get" + field.getName()));
		getMD.setReturnType2((Type) field.getType().copySubtree(ast, field.getType()));
		getMD.setJavadoc((Javadoc) field.getJavadoc().copySubtree(ast, field.getJavadoc()));
		return getMD;
	}

	@SuppressWarnings("unchecked")
	public static MethodDeclaration genSetMethodSignature(final AST ast, final Field field) {
		final MethodDeclaration setMD = ast.newMethodDeclaration();
		setMD.setName(ast.newSimpleName("set" + field.getName()));
		final SingleVariableDeclaration param = ast.newSingleVariableDeclaration();
		param.setName(field.getName());
		param.setType((Type) field.getType().copySubtree(ast, field.getType()));
		setMD.parameters().add(param);
		setMD.setJavadoc((Javadoc) field.getJavadoc().copySubtree(ast, field.getJavadoc()));
		return setMD;
	}
}
